package com.pipayshop.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pipayshop.entity.*;
import com.pipayshop.entity.dto.RoomDto;
import com.pipayshop.entity.dto.ShopCommodityLiveInfoListDTO1;
import com.pipayshop.entity.dto.ShopHotelRecordDTO;
import com.pipayshop.entity.vo.*;
import com.pipayshop.exception.BusinessException;
import com.pipayshop.mapper.*;
import com.pipayshop.service.HotelShopCommodityLiveInfoService;
import com.pipayshop.service.HotelShopHotelRecordService;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.pipayshop.utils.FileUploadUtil;
import com.pipayshop.utils.StringUtil;
import com.pipayshop.utils.ValidationUtil;
import jakarta.annotation.Resource;
import org.apache.commons.lang3.StringUtils;
import org.modelmapper.ModelMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 酒店的房型表 服务实现类
 * </p>
 *
 * @author zxb
 * @since 2023-08-02
 */
@Service
public class HotelShopCommodityLiveInfoServiceImpl extends ServiceImpl<HotelShopCommodityLiveInfoMapper, ShopCommodityLiveInfo> implements HotelShopCommodityLiveInfoService {

    @Resource
    private HotelShopCommodityLiveInfoMapper shopCommodityLiveInfoMapper;

    @Resource
    private ObjectMapper objectMapper;

    @Resource
    private HotelShopEvaluateMapper shopEvaluateMapper;

    @Resource
    private HotelShopOrderInfoMapper shopOrderInfoMapper;

    @Resource
    private HotelShopHotelRecordMapper shopHotelRecordMapper;

    @Resource
    HotelShopInfoMapper shopInfoMapper;

    @Resource
    ImageMapper imageMapper;

    /**
     * 根据房型id查找房型的详细信息
     */
    @Override
    public ShopCommodityLiveInfoVO5 selectShopLiveByRoomId(String roomId) {
        ShopCommodityLiveInfoVO shopCommodityLiveInfoVO = shopCommodityLiveInfoMapper.selectByRoomId(roomId);
        return convertJsonFields(shopCommodityLiveInfoVO, roomId);
    }

    @Transactional(rollbackFor = Exception.class)
    public ShopCommodityLiveInfoVO5 convertJsonFields(ShopCommodityLiveInfoVO shopCommodityLiveInfoVO, String roomId) {
        ShopCommodityLiveInfoVO5 shopCommodityLiveInfoVO5=new ShopCommodityLiveInfoVO5();
        try {
            BeanUtils.copyProperties(shopCommodityLiveInfoVO,shopCommodityLiveInfoVO5);
            shopCommodityLiveInfoVO5.setBasics(parseJsonList(shopCommodityLiveInfoMapper.getBasic(roomId)));
            shopCommodityLiveInfoVO5.setImageId(JSON.parseArray(shopCommodityLiveInfoVO.getImageList(), String.class));
            JSONArray imageArray = JSON.parseArray(shopCommodityLiveInfoVO.getImageList());
            shopCommodityLiveInfoVO5.setImageList(getImagesFromIds(JSON.parseArray(imageArray.toJSONString(), String.class)));
            shopCommodityLiveInfoVO5.setBath(parseJsonList(shopCommodityLiveInfoMapper.getBath(roomId)));
            shopCommodityLiveInfoVO5.setAppliance(parseJsonList(shopCommodityLiveInfoMapper.getAppliance(roomId)));
        } catch (JsonProcessingException e) {
            throw new BusinessException("json_parsing_failed");
        }
        return shopCommodityLiveInfoVO5;
    }

    private <T> List<T> parseJsonList(String json) throws JsonProcessingException {
        return json != null ? objectMapper.readValue(json, new TypeReference<List<T>>() {
        }) : new ArrayList<>();
    }

    /**
     * 增加房型的详细信息
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean insertShopLiveInfo(ShopCommodityLiveInfoVO1 shopCommodityLiveInfoVO1) {
        // 数据校验
        ValidationUtil.validateString(shopCommodityLiveInfoVO1.getRoomTypeName(), "room_type_name_required");
        ValidationUtil.validatePositiveNumber(shopCommodityLiveInfoVO1.getInventory(), "room_type_inventory_must_be_positive");
        ValidationUtil.validatePositiveBigDecimal(shopCommodityLiveInfoVO1.getPrice(), "price_must_be_positive");
        ValidationUtil.validatePositiveNumber(shopCommodityLiveInfoVO1.getLand(), "land_area_must_be_positive");
        ValidationUtil.validatePositiveNumber(shopCommodityLiveInfoVO1.getRoom(), "room_count_must_be_positive");
        ValidationUtil.validatePositiveNumber(shopCommodityLiveInfoVO1.getRestRoom(), "restroom_count_cannot_be_negative");
        ValidationUtil.validatePositiveNumber(shopCommodityLiveInfoVO1.getBed(), "bed_count_must_be_positive");
        ValidationUtil.validatePositiveNumber(shopCommodityLiveInfoVO1.getAdult(), "adult_capacity_cannot_be_negative");
        ValidationUtil.validateListNotEmpty(shopCommodityLiveInfoVO1.getImageList(), "room_type_image_required");
        // 属性转移
        ShopCommodityLiveInfo shopCommodityLiveInfo = mapToShopCommodityLiveInfo(shopCommodityLiveInfoVO1);

        // 更新商品库存
        int shopId = shopInfoMapper.updateCommodityBalance(shopCommodityLiveInfo.getShopId());
        if (shopId < 1) {
            throw new BusinessException("commodity_stock_update_failed");
        }
        // 插入房型数据
        return shopCommodityLiveInfoMapper.insert(shopCommodityLiveInfo) > 0;
    }

    private ShopCommodityLiveInfo mapToShopCommodityLiveInfo(ShopCommodityLiveInfoVO1 shopCommodityLiveInfoVO1) {
        ShopCommodityLiveInfo shopCommodityLiveInfo = new ShopCommodityLiveInfo();
        BeanUtils.copyProperties(shopCommodityLiveInfoVO1, shopCommodityLiveInfo);
        String roomId = StringUtil.generateShortId();
        shopCommodityLiveInfo.setRoomId(roomId);
        shopCommodityLiveInfo.setTagList(JSON.toJSONString(shopCommodityLiveInfoVO1.getTagList()));
        shopCommodityLiveInfo.setImageList(JSON.toJSONString(shopCommodityLiveInfoVO1.getImageList()));
        shopCommodityLiveInfo.setBasics(JSON.toJSONString(shopCommodityLiveInfoVO1.getBasics()));
        shopCommodityLiveInfo.setBath(JSON.toJSONString(shopCommodityLiveInfoVO1.getBath()));
        shopCommodityLiveInfo.setAppliance(JSON.toJSONString(shopCommodityLiveInfoVO1.getAppliance()));
        shopCommodityLiveInfo.setRecommended(isVip(shopCommodityLiveInfoVO1.getShopId()) ? 1 : 0);
        shopCommodityLiveInfo.setAvatarImag(shopCommodityLiveInfoVO1.getImageList().get(0));
        shopCommodityLiveInfo.setDelFlag(0);
        shopCommodityLiveInfo.setPiFlag(shopCommodityLiveInfoVO1.getPiFlag());
        return shopCommodityLiveInfo;
    }
    private boolean isVip(String shopId) {
        return shopInfoMapper.selectCount(new QueryWrapper<HotelShopInfo>()
                .eq("shop_id", shopId)
                .eq("membership", 1)).intValue() == 1;
    }


    /**
     * 修改房型的详细信息
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean updateHotelInfoByRoomId(ShopCommodityLiveInfoVO4 shopCommodityLiveInfoVO4) {
        // 数据校验
        ValidationUtil.validateString(shopCommodityLiveInfoVO4.getRoomId(), "room_type_id_required");
        ValidationUtil.validateString(shopCommodityLiveInfoVO4.getRoomTypeName(), "room_type_name_required");
        ValidationUtil.validatePositiveNumber(shopCommodityLiveInfoVO4.getInventory(), "room_type_inventory_must_be_positive");
        ValidationUtil.validatePositiveBigDecimal(shopCommodityLiveInfoVO4.getPrice(), "price_must_be_positive");
        ValidationUtil.validatePositiveNumber(shopCommodityLiveInfoVO4.getLand(), "land_area_must_be_positive");
        ValidationUtil.validatePositiveNumber(shopCommodityLiveInfoVO4.getRoom(), "room_count_must_be_positive");
        ValidationUtil.validatePositiveNumber(shopCommodityLiveInfoVO4.getBed(), "bed_count_must_be_positive");
        ValidationUtil.validatePositiveNumber(shopCommodityLiveInfoVO4.getAdult(), "adult_capacity_cannot_be_negative");
        ValidationUtil.validateListNotEmpty(shopCommodityLiveInfoVO4.getImageList(), "room_type_image_required");
        if (shopCommodityLiveInfoVO4.getDeleteImageList() != null && !shopCommodityLiveInfoVO4.getDeleteImageList().isEmpty()) {
            if (shopInfoMapper.updateDelFlag(shopCommodityLiveInfoVO4.getDeleteImageList()) == 0) {
                throw new BusinessException("image_usage_update_failed");
            }
        }
        // 属性转移
        ShopCommodityLiveInfo shopCommodityLiveInfo = UpdateShopCommodityLiveInfo(shopCommodityLiveInfoVO4);

        // 更新房型信息
        int result = shopCommodityLiveInfoMapper.update(shopCommodityLiveInfo, new QueryWrapper<ShopCommodityLiveInfo>()
                .eq("room_id", shopCommodityLiveInfo.getRoomId()));
        return result > 0;
    }

    private ShopCommodityLiveInfo UpdateShopCommodityLiveInfo(ShopCommodityLiveInfoVO4 shopCommodityLiveInfoVO4) {
        ShopCommodityLiveInfo shopCommodityLiveInfo = new ShopCommodityLiveInfo();
        BeanUtils.copyProperties(shopCommodityLiveInfoVO4, shopCommodityLiveInfo);

        shopCommodityLiveInfo.setTagList(JSON.toJSONString(shopCommodityLiveInfoVO4.getTagList()));
        shopCommodityLiveInfo.setImageList(JSON.toJSONString(shopCommodityLiveInfoVO4.getImageList()));
        shopCommodityLiveInfo.setBasics(JSON.toJSONString(shopCommodityLiveInfoVO4.getBasics()));
        shopCommodityLiveInfo.setBath(JSON.toJSONString(shopCommodityLiveInfoVO4.getBath()));
        shopCommodityLiveInfo.setAppliance(JSON.toJSONString(shopCommodityLiveInfoVO4.getAppliance()));
        shopCommodityLiveInfo.setDelFlag(0);
        return shopCommodityLiveInfo;
    }
    /**
     * 根据房型id更改房型的详细信息（这个方法没用到）
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean updateShopLiveInfo(ShopCommodityLiveInfo shopCommodityLiveInfo) {
        int result = shopCommodityLiveInfoMapper.update(shopCommodityLiveInfo, new QueryWrapper<ShopCommodityLiveInfo>()
                .eq("room_id", shopCommodityLiveInfo.getRoomId()));
        return result > 0;
    }


    /**
     * 根据房型id删除房型的详细信息
     */
    @Override
    public boolean deleteShopLiveInfo(String roomId) {
        return shopCommodityLiveInfoMapper.update(null, new UpdateWrapper<ShopCommodityLiveInfo>()
                .eq("room_id", roomId)
                .set("del_flag", 1)) > 0;
    }

    /**
     * 根据实体店id和入住时间和离店时间来搜索房型
     *
     * @param shopId
     * @param startTime
     * @param endTime
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public List<ShopCommodityLiveInfoListVO> selectShopCommodityLiveInfoList(String shopId, Date startTime, Date endTime) {
        List<ShopCommodityLiveInfoListVO> shopCommodityLiveInfoListVOS = shopCommodityLiveInfoMapper.selectShopCommodityLiveInfoList(shopId);
        shopCommodityLiveInfoListVOS.forEach(commodity -> commodity.setInventory(getInventory(commodity.getRoomId(), startTime, endTime)));
        return shopCommodityLiveInfoListVOS;
    }
    @Override
    public Integer getInventory(String roomId, Date startTime, Date endTime) {
        // 根据 roomId 找库存
        Integer inventory = shopCommodityLiveInfoMapper.selectOne(new QueryWrapper<ShopCommodityLiveInfo>()
                        .eq("room_id", roomId))
                .getInventory();
        Integer rent = shopHotelRecordMapper.getRentByTime(roomId, startTime, endTime);
        return inventory - rent;
    }
    /**
     * 获取实体店评价数
     */
    @Override
    public Integer selectShopEvaluateCount(String shopId) {

        return shopEvaluateMapper.selectShopEvaluateCount(shopId);
    }

    /**
     * 提交入住酒店
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean applyShopCommodityLive(ShopHotelRecordDTO shopHotelRecordDTO) {
        // 数据校验
        ValidationUtil.validateString(shopHotelRecordDTO.getRoomId(), "room_type_id_required");
        ValidationUtil.validateString(shopHotelRecordDTO.getName(), "name_required");
        ValidationUtil.validateString(shopHotelRecordDTO.getPhone(), "phone_number_required");
        ValidationUtil.validateNotNull(shopHotelRecordDTO.getStartTime(), "check_in_time_required");
        ValidationUtil.validateNotNull(shopHotelRecordDTO.getEndTime(), "check_out_time_required");
        ValidationUtil.validatePositiveBigDecimal(shopHotelRecordDTO.getTransactionAmount(), "transaction_amount_must_be_positive");
        ValidationUtil.validateString(shopHotelRecordDTO.getCommodityId(), "commodity_id_required");
        ValidationUtil.validateString(shopHotelRecordDTO.getUid(), "user_id_required");
        // 生成订单ID并插入订单信息
        String orderId = StringUtil.generateShortId();
        insertOrderInfo(shopHotelRecordDTO, orderId);

        // 插入入住记录
        return insertHotelRecord(shopHotelRecordDTO, orderId);
    }


    private boolean insertOrderInfo(ShopHotelRecordDTO shopHotelRecordDTO, String orderId) {
        // 创建 HotelStoreOrderInfo 实体并赋值
        HotelStoreOrderInfo hotelStoreOrderInfo = new HotelStoreOrderInfo();
        hotelStoreOrderInfo.setOrderId(orderId);
        hotelStoreOrderInfo.setCommodityId(shopHotelRecordDTO.getCommodityId());
        hotelStoreOrderInfo.setTransactionAmount(shopHotelRecordDTO.getTransactionAmount());
        hotelStoreOrderInfo.setUid(shopHotelRecordDTO.getUid());
        hotelStoreOrderInfo.setShopId(shopHotelRecordDTO.getShopId());
        hotelStoreOrderInfo.setOrderStatus(1); // 设置为下单状态

        // 插入订单信息到数据库
        return shopOrderInfoMapper.insert(hotelStoreOrderInfo) > 0;
    }


    private boolean insertHotelRecord(ShopHotelRecordDTO shopHotelRecordDTO, String orderId) {
      // 创建 ShopHotelRecord 实体并赋值
        ShopHotelRecord shopHotelRecord = new ShopHotelRecord();
        shopHotelRecord.setRecordId(StringUtil.generateShortId());
        shopHotelRecord.setRoomId(shopHotelRecordDTO.getRoomId());
        shopHotelRecord.setName(shopHotelRecordDTO.getName());
        shopHotelRecord.setPhone(shopHotelRecordDTO.getPhone());
        shopHotelRecord.setStartTime(shopHotelRecordDTO.getStartTime());
        shopHotelRecord.setEndTime(shopHotelRecordDTO.getEndTime());
        shopHotelRecord.setOrderId(orderId);

        // 插入入住记录到数据库
        return shopHotelRecordMapper.insert(shopHotelRecord) > 0;
    }


    @Override
    @Transactional(rollbackFor = Exception.class)
    public PageDataVO selectShopCommodityLiveInfoVO(Integer limit, Integer pages) {
        Integer integer = shopCommodityLiveInfoMapper.selectAllShopCommodityLiveVO();
        List<ShopCommodityLiveVO> shopCommodityLiveVOS = shopCommodityLiveInfoMapper.selectShopCommodityLiveVO(limit, (pages - 1) * limit);
        return new PageDataVO(integer, shopCommodityLiveVOS);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean insertShopLive(ShopCommodityLiveInfo shopCommodityLiveInfo) {
        // 数据校验
        ValidationUtil.validateString(shopCommodityLiveInfo.getRoomTypeName(), "room_type_name_required");
        ValidationUtil.validatePositiveNumber(shopCommodityLiveInfo.getInventory(), "commodity_inventory_must_be_positive");
        ValidationUtil.validatePositiveBigDecimal(shopCommodityLiveInfo.getPrice(), "price_must_be_positive");
        ValidationUtil.validatePositiveNumber(shopCommodityLiveInfo.getLand(), "land_area_must_be_positive");
        ValidationUtil.validatePositiveNumber(shopCommodityLiveInfo.getRoom(), "room_count_must_be_positive");
        ValidationUtil.validatePositiveNumber(shopCommodityLiveInfo.getBed(), "bed_count_must_be_positive");
        // 如果所有校验通过，生成房型ID并插入
        shopCommodityLiveInfo.setRoomId(StringUtil.generateShortId());
        int result = shopCommodityLiveInfoMapper.insert(shopCommodityLiveInfo);
        return result > 0;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean updateShopLive(ShopCommodityLiveInfoUpVO shopCommodityLiveInfoUpVO) {
        // 数据校验
        ValidationUtil.validateString(shopCommodityLiveInfoUpVO.getRoomId(), "room_type_id_required");
        ValidationUtil.validateString(shopCommodityLiveInfoUpVO.getRoomTypeName(), "room_type_name_required");

        ValidationUtil.validatePositiveNumber(shopCommodityLiveInfoUpVO.getInventory(), "commodity_inventory_must_be_positive");

        ValidationUtil.validatePositiveBigDecimal(shopCommodityLiveInfoUpVO.getPrice(), "price_must_be_positive");

        ValidationUtil.validatePositiveNumber(shopCommodityLiveInfoUpVO.getLand(), "land_area_must_be_positive");

        ValidationUtil.validatePositiveNumber(shopCommodityLiveInfoUpVO.getRoom(), "room_count_must_be_positive");

        ValidationUtil.validatePositiveNumber(shopCommodityLiveInfoUpVO.getBed(), "bed_count_must_be_positive");

        ValidationUtil.validatePositiveNumber(shopCommodityLiveInfoUpVO.getAdult(), "adult_capacity_cannot_be_negative");

        // 数据构建
        ShopCommodityLiveInfo shopCommodityLiveInfo = new ShopCommodityLiveInfo(null,
                shopCommodityLiveInfoUpVO.getRoomId(), shopCommodityLiveInfoUpVO.getRoomTypeName(),
                null, shopCommodityLiveInfoUpVO.getInventory(), shopCommodityLiveInfoUpVO.getDetail(),
                shopCommodityLiveInfoUpVO.getTagList(), shopCommodityLiveInfoUpVO.getImageList(),
                shopCommodityLiveInfoUpVO.getLand(), shopCommodityLiveInfoUpVO.getRoom(),
                shopCommodityLiveInfoUpVO.getRestRoom(), shopCommodityLiveInfoUpVO.getBed(),
                shopCommodityLiveInfoUpVO.getAdult(), shopCommodityLiveInfoUpVO.getChildren(),
                shopCommodityLiveInfoUpVO.getRestricted(), shopCommodityLiveInfoUpVO.getBasics(),
                shopCommodityLiveInfoUpVO.getBath(), shopCommodityLiveInfoUpVO.getAppliance(),
                shopCommodityLiveInfoUpVO.getPrice(), null, null, shopCommodityLiveInfoUpVO.getAvatarImag(),
                null, shopCommodityLiveInfoUpVO.getBedType(), shopCommodityLiveInfoUpVO.getFloor(),
                shopCommodityLiveInfoUpVO.getIsAdd(), null, shopCommodityLiveInfoUpVO.getPiFlag());

        // 执行更新
        int result = shopCommodityLiveInfoMapper.update(shopCommodityLiveInfo,
                new UpdateWrapper<ShopCommodityLiveInfo>().eq("room_id", shopCommodityLiveInfoUpVO.getRoomId()));
        return result > 0;
    }


    @Override
    public String roomTopImageUp(MultipartFile multipartFile) {
        return uploadImage(multipartFile, FileUploadUtil.ROOM_TOP_IMG);
    }

    @Override
    public String roomImageUp(MultipartFile multipartFile) {
        return uploadImage(multipartFile, FileUploadUtil.ROOM_IMAGE_LIST);
    }

    private String uploadImage(MultipartFile multipartFile, String imageType) {
        return FileUploadUtil.allUploadImageData(multipartFile, imageMapper, imageType, null);
    }

    /**
     * 根据价格升降序，价格条件可有可无
     *
     * @param shopInfo
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public List<ShopCommodityLiveInfoVO2> selectAllByPrice(ShopCommodityLiveInfoListDTO1 shopInfo)  {
        ValidationUtil.validateString(shopInfo.getStatus(), "status_required");
        List<ShopCommodityLiveInfoVO3> shopInfoLists = shopCommodityLiveInfoMapper.selectALlByPrice(shopInfo);
        List<ShopCommodityLiveInfoVO2> shopInfoLists2 = new ArrayList<>();
        for (ShopCommodityLiveInfoVO3 shopInfoVO : shopInfoLists) {
            if (shopInfoVO != null) {
                // System.out.println(shopInfoVO);
                ModelMapper modelMapper = new ModelMapper();
                //接收转换后的值
                ShopCommodityLiveInfoVO2 s2 = modelMapper.map(shopInfoVO, ShopCommodityLiveInfoVO2.class);
                //tagList
                JSONArray TagArray = JSON.parseArray(shopInfoVO.getTagList());
                List<String> tagList = JSON.parseArray(TagArray.toJSONString(), String.class);
                s2.setTagList(tagList);
                //imageList
                JSONArray imageArray = JSON.parseArray(shopInfoVO.getImageList());
                List<String> imageList = getImagesFromIds(JSON.parseArray(imageArray.toJSONString(), String.class));
                s2.setImageList(imageList);
                //  解析基础设施
                JSONArray basicArray = JSON.parseArray(shopInfoVO.getBasics());
                List<HotelFacilityVO> basicList = JSON.parseArray(basicArray.toJSONString(), HotelFacilityVO.class);
                s2.setBasics(basicList);
                JSONArray bathArray = JSON.parseArray(shopInfoVO.getBath());
                List<HotelFacilityVO> bathList = JSON.parseArray(bathArray.toJSONString(), HotelFacilityVO.class);
                s2.setBath(bathList);
                JSONArray applianceArray = JSON.parseArray(shopInfoVO.getAppliance());
                List<HotelFacilityVO> applianceList = JSON.parseArray(applianceArray.toJSONString(), HotelFacilityVO.class);
                s2.setAppliance(applianceList);
                shopInfoLists2.add(s2);
            }
        }
        return shopInfoLists2;
    }

    private List<String> getImagesFromIds(List<String> imageIds) {
        return imageIds.stream()
                .map(imageMapper::selectPath)
                .collect(Collectors.toList());
    }


    /**
     * 修改房间状态
     *
     * @param room
     * @return
     */
    @Override
    public int updateRoomStatus(RoomDto room) {
        // 数据校验
        ValidationUtil.validateString(room.getRoomId(), "room_type_id_required");

        ValidationUtil.validateNotNull(room.getStatus(), "room_type_status_required");

        // 更新房型状态
        UpdateWrapper<ShopCommodityLiveInfo> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("room_id", room.getRoomId())
                .set("status", room.getStatus());
        int update = shopCommodityLiveInfoMapper.update(null, updateWrapper);
        return update;
    }

}
